//
//  ByFootBallScoreBetCell.m
//  caipiao_ios
//
//  Created by mc on 2018/7/20.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByFootBallScoreBetCell.h"
#import "ByFootBallTitleView.h"


@implementation ByFootBallScoreBetCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByFootBallScoreBetCell";
    ByFootBallScoreBetCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
        
       
    }
    return self;
}


- (void)initViews{
    
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    UIView *backgroundView = [[UIView alloc] init];
    backgroundView.layer.cornerRadius = 10;
    backgroundView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(0);
        make.left.equalTo(self.contentView).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];
    
    
    ByFootBallTitleView *titleView = [[ByFootBallTitleView alloc] init];
    [backgroundView addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(backgroundView).offset(0);
        make.height.mas_equalTo(@85);
    }];
    self.titleView = titleView;
    
    UIButton *scoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backgroundView addSubview:scoreBtn];
    [scoreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleView.mas_bottom).offset(0);
        make.centerX.equalTo(backgroundView).offset(0);
        make.width.mas_equalTo(@(SCREEN_WIDTH - 100));
        make.bottom.equalTo(backgroundView).offset(-20);
    }];
    scoreBtn.backgroundColor = rgba(252, 243, 209, 1);
    scoreBtn.titleLabel.numberOfLines = 0;
    [scoreBtn setTitle:@"点击选择比分投注" forState:UIControlStateNormal];
    [scoreBtn setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
    [scoreBtn addTarget:self action:@selector(scoreAction:) forControlEvents:UIControlEventTouchUpInside];
    self.scoreBtn = scoreBtn;
}

- (void)scoreAction:(UIButton *)btn{
    if (self.scoreBetBlock) {
        self.scoreBetBlock();
    }
}

- (void)setDataArray:(NSMutableArray *)dataArray{
    _dataArray = dataArray;
    
     [self initViews];

    NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:1];
    for (ByNetModel *netModel in dataArray){
            if (netModel.selected) {
                [tempArray addObject:netModel.title];
            }
    }
    if (tempArray.count > 0) {
        [self.scoreBtn setTitle:[tempArray componentsJoinedByString:@","] forState:UIControlStateNormal];
        self.scoreBtn.titleLabel.font = FONT(14);
    }else{
         self.scoreBtn.titleLabel.font = FONT(18);
    }
}


@end
